import type { UploadUserFile } from "element-plus";

export interface GetSpuListApiParams {
  page: number;
  limit: number;
  category3Id: number;
}

/*
  {
    "records": [
      {
        "id": 3748,
        "spuName": "HTC",
        "description": "12",
        "category3Id": 61,
        "tmId": 24,
        "spuSaleAttrList": null,
        "spuImageList": null
      }
    ],
    "total": 10,
    "size": 1,
    "current": 1,
    "searchCount": true,
    "pages": 10
  }
*/
export interface SpuItem {
  id?: number;
  category3Id?: number;
  spuName: string;
  tmId?: number;
  description: string;
}

export interface SpuSaleAttrValueItem {
  baseSaleAttrId: number;
  saleAttrValueName: string;
  id?: number;
  isChecked?: string;
  saleAttrName?: string;
  spuId?: number;
}

export type SpuSaleAttrValueList = SpuSaleAttrValueItem[];

export interface SpuSaleAttrItem {
  baseSaleAttrId: number;
  saleAttrName: string;
  isShowEdit?: boolean;
  id?: number;
  spuId?: number;
  spuSaleAttrValueList: SpuSaleAttrValueList;
}

export type SpuSaleAttrList = SpuSaleAttrItem[];

export interface SpuFormData extends SpuItem {
  spuImageList: UploadUserFile[];
  spuSaleAttrList: SpuSaleAttrList;
}

export interface SpuImageItem {
  id?: number;
  imgName: string;
  imgUrl: string;
  spuId?: number;
  isDefault?: "0" | "1";
}

export type SpuImageList = SpuImageItem[];

export interface AddOrUpdateSpuParams extends SpuItem {
  spuImageList: SpuImageList;
  spuSaleAttrList: SpuSaleAttrList;
}

export type SpuList = SpuItem[];

export interface GetSpuListApiResponse {
  records: SpuList;
  total: number;
  // size: number;
  // current: number;
  // searchCount: boolean;
  // pages: number;
}

export interface BaseSaleAttrItem {
  id: number;
  name: string;
}

export type BaseSaleAttrList = BaseSaleAttrItem[];

/*
  SpuList展示数据类型spuList
    数组本身没啥，关键在数组中的对象
    {
      id: number;
      spuName: string;
      description: string;
    }
  添加Spu组件，需要的spuFormData数据类型
    {
      spuName: string;
      tmId: number;
      description: string;
      // 组件spuImageList是给el-upload的v-model双向数据绑定的
      // 所以数据类型要符合el-upload组件类型定义（不符合会报类型错误）。看文档
      spuImageList: UploadUserFile[];
      spuSaleAttrList: [
        {
          baseSaleAttrId: number;
          saleAttrName: string;
          isShowEdit: boolean;
          spuSaleAttrValueList: [
            {
              baseSaleAttrId: number;
              saleAttrValueName: string;
            }
          ]
        }
      ];
    }

  添加Spu接口参数类型
    {
      "category3Id": number,
      "description": "string",
      "spuImageList": [
        {
          "imgName": "string",
          "imgUrl": "string",
        }
      ],
      "spuName": "string",
      "spuSaleAttrList": [
        {
          "baseSaleAttrId": 0,
          "saleAttrName": "string",
          "spuSaleAttrValueList": [
            {
              "baseSaleAttrId": 0,
              "saleAttrValueName": "string",
            }
          ]
        }
      ],
      "tmId": number
    }

  修改Spu接口参数类型

    {
      "category3Id": 0,
      "description": "string",
      "id": 0,
      "spuImageList": [
        {
          "id": 0,
          "imgName": "string",
          "imgUrl": "string",
          "spuId": 0
        }
      ],
      "spuName": "string",
      "spuSaleAttrList": [
        {
          "baseSaleAttrId": 0,
          "id": 0,
          "saleAttrName": "string",
          "spuId": 0,
          "spuSaleAttrValueList": [
            {
              "baseSaleAttrId": 0,
              "saleAttrValueName": "string",
              "id": 0,
              "isChecked": "string",
              "saleAttrName": "string",
              "spuId": 0
            }
          ]
        }
      ],
      "tmId": 0
    }


  1. 分析每个情况需要什么类型
  2. 共有类型定义成必选属性，独有类型定义成可选属性
*/
